<template>
  <div class="app-container">
    <el-card class="box-card" shadow="never">
      <el-tabs v-model="activeName">
        <el-tab-pane label="机构信息" name="first">
          <div v-for="(value, key) in merchantKeys" :key="key" class="basic-info-item">
            <span class="column-name">{{ value }}</span>
            <span>{{ convertMerchantKey(key) }} </span>
          </div>
        </el-tab-pane>

        <el-tab-pane label="联系人信息" name="sec">
          <div v-for="(value, key) in merchantContactKeys" :key="key" class="basic-info-item">
            <span class="column-name">{{ value }}</span>
            <span>{{ convertContactKey(key) }} </span>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { getMerchantDetail, getMerchantContact } from '@/api/merchant'
import dayjs from 'dayjs'

export default {
  data() {
    return {
      merchantInfo: {},
      merchantContact: {},
      activeName: 'first',
      merchantKeys: {
        name: '机构名称',
        tel: '联系电话',
        address: '机构地址',
        regionName: '所在区域',
        businessHours: '营业时间',
        intro: '介绍',
        courseCategories: '主营课程',
        startDate: '注册时间',
        accountTypeTxt: '账户类型',
        expireTime: '到期时间'
      },
      merchantContactKeys: {
        name: '联系人',
        mobile: '联系电话'
      }
    }
  },
  mounted() {
    this.getMerchantDetail()
    this.getMerchantContact()
  },
  methods: {
    getMerchantDetail() {
      getMerchantDetail().then(res => {
        this.merchantInfo = res.data
      })
    },
    convertMerchantKey(key) {
      this.merchantInfo['startDate'] = dayjs(this.merchantInfo['startDate']).format('YYYY-MM-DD')
      this.merchantInfo['expireTime'] = dayjs(this.merchantInfo['expireTime']).format('YYYY-MM-DD')
      return this.merchantInfo[key]
    },
    getMerchantContact() {
      getMerchantContact().then(res => {
        if (res.data.list != null)
        this.merchantContact = res.data.list[0]
      })
    },
    convertContactKey(key) {
      return this.merchantContact[key]
    }
  }
}
</script>
